FROM xiejianshan/px4-gazebo-1804:1.0 AS gazebo_building_stage
# COPY models/livox_mid360 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/livox_mid360
COPY models/iris_livox_mid360 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_livox_mid360
COPY models/iris_livox_mid360_0 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_livox_mid360_0
COPY models/iris_livox_mid360_1 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_livox_mid360_1
COPY models/iris_livox_mid360_2 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_livox_mid360_2
COPY models/iris_livox_mid360_3 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_livox_mid360_3
COPY models/iris_livox_mid360_4 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_livox_mid360_4
COPY models/iris_livox_mid360_5 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_livox_mid360_5

COPY models/iris_0 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_0
COPY models/iris_1 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_1
COPY models/iris_2 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_2
COPY models/iris_3 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_3
COPY models/iris_4 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_4
COPY models/iris_5 /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_5

COPY meshes /home/src/PX4-Autopilot/Tools/sitl_gazebo/livox_mid360_meshes
# copy for RealSense Plugins 
COPY realsense /home/src/PX4-Autopilot/Tools/sitl_gazebo/realsense_plugins  
# 虽然不知道为啥这个资源要单独放一个文件夹,但是为了和xjs写的一致还是这样写了
COPY models/iris_realsense /home/src/PX4-Autopilot/Tools/sitl_gazebo/models/iris_realsense

COPY launch/*.launch /home/src/PX4-Autopilot/launch/
RUN make px4_sitl_default gazebo
# 这部分编译了Gazebo相关的
FROM osrf/ros:melodic-desktop-full

ARG PX4_WS=/home/px4_ws
ARG WORLD_REPO=https://gitee.com/xiejianshan/gazebo_world_ws/raw/master/iusc_world/worlds
ARG LIVOX_MESHES=${PX4_WS}/Tools/sitl_gazebo/livox_mid360_meshes

WORKDIR ${PX4_WS}

COPY --from=gazebo_building_stage /home/src/PX4-Autopilot/build ${PX4_WS}/build
COPY --from=gazebo_building_stage /home/src/PX4-Autopilot/launch ${PX4_WS}/launch
COPY --from=gazebo_building_stage /home/src/PX4-Autopilot/ROMFS ${PX4_WS}/ROMFS
COPY --from=gazebo_building_stage /home/src/PX4-Autopilot/Tools ${PX4_WS}/Tools
COPY --from=gazebo_building_stage /home/src/PX4-Autopilot/package.xml ${PX4_WS}/package.xml
# for iusc outdoor gazebo sh 
COPY gazebo_run ${PX4_WS}/gazebo_run
COPY multi_gazebo_run ${PX4_WS}/multi_gazebo_run
# for iusc indoor gazebo sh
COPY single_iusc_indoor_sim ${PX4_WS}/single_iusc_indoor_sim

COPY worlds/light/green_light /root/.gazebo/models/green_light
COPY worlds/light/red_light /root/.gazebo/models/red_light

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AD19BAB3CBF125EA

RUN sed -i "5 i export PX4_WS=${PX4_WS}" ${PX4_WS}/gazebo_run &&\
    sed -i "6 i export WORLD_REPO=${WORLD_REPO}" ${PX4_WS}/gazebo_run &&\
    sed -i "5 i export PX4_WS=${PX4_WS}" ${PX4_WS}/multi_gazebo_run &&\
    sed -i "6 i export WORLD_REPO=${WORLD_REPO}" ${PX4_WS}/multi_gazebo_run &&\
    sed -i "5 i export PX4_WS=${PX4_WS}" ${PX4_WS}/single_iusc_indoor_sim &&\
    sed -i "6 i export WORLD_REPO=${WORLD_REPO}" ${PX4_WS}/single_iusc_indoor_sim &&\
    # 修改livox_mid360.sdf参数文件路径
    # sed -i "73 c \<plugin name=\'gazebo_ros_laser_controller\' filename=\'${LIVOX_MESHES}\/liblivox_laser_simulation.so\'\>" ${PX4_WS}/Tools/sitl_gazebo/models/livox_mid360/livox_mid360.sdf &&\
    # sed -i "103 c \<csv_file_name\>${LIVOX_MESHES}\/mid360.csv\<\/csv_file_name\>" ${PX4_WS}/Tools/sitl_gazebo/models/livox_mid360/livox_mid360.sdf &&\
    echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc &&\
    # 下载wget, xmlstarlet
    apt-get -y update &&\
    apt-get -y install wget xmlstarlet&&\
    # 下载mavros
    apt-get -y install ros-melodic-mavros ros-melodic-mavros-extras &&\
    wget https://gitee.com/xiejianshan/shieh_file_for_everything/releases/download/shieh_utils_1.1/GeographicLib.tar.xz &&\
    tar -xf GeographicLib.tar.xz &&\
    mv GeographicLib /usr/share/ &&\
    rm GeographicLib.tar.xz &&\
    apt-get clean all &&\
    rm -rf /var/cache/apt &&\
    rm -rf /var/lib/apt/lists/*


WORKDIR /home/temp
 